package jihe;
/**
 * 发牌已排序
 */
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeSet;

/**
 * 斗地主发牌器
 */
public class DouDiZhu02 {
    ArrayList<Integer> arrayList = new ArrayList<Integer>();
    HashMap<Integer, String> hashMap = new HashMap<Integer, String>(); // 创建一个HashMap集合
    /**
     * 初始化54张牌
     */
    public void init() {
        int index = 0;
        String [] numbers = { "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2",};
        String [] colors = {"♠","♥","♣","♦"};
        for (String number : numbers) {
            for (String color : colors) {
                String poker = color.concat(number);
                hashMap.put(index, poker);
                arrayList.add(index);
                index++;
            }
        }
        hashMap.put(index, "小王");
        arrayList.add(index);
        index++;
        hashMap.put(index, "大王");
        arrayList.add(index);
    }
    /**
     * 洗牌
     */
    public void ShuffleCards(){
        Collections.shuffle(arrayList);
    }
    /**
     * 发牌
     */
    public void LicensePlate(){
        TreeSet<Integer> gamer1 = new TreeSet<Integer>();
        TreeSet<Integer> gamer2 = new TreeSet<Integer>();
        TreeSet<Integer> gamer3 = new TreeSet<Integer>();
        TreeSet<Integer> hand = new TreeSet<Integer>();
        for (int i = 0; i < arrayList.size(); i++) {
            if (i >= arrayList.size() - 3) {
                hand.add((Integer) arrayList.get(i));
            } else if (i % 3 == 0) {
                gamer1.add((Integer) arrayList.get(i));
            } else if (i % 3 == 1) {
                gamer2.add((Integer) arrayList.get(i));
            } else if (i % 3 == 2) {
                gamer3.add((Integer) arrayList.get(i));
            }
        }
        lookPoker("地主", gamer1, hashMap);
        lookPoker("农民1", gamer2, hashMap);
        lookPoker("农民2", gamer3, hashMap);
        lookPoker("底牌", hand, hashMap);
    }
    // 写看牌的功能
    public static void lookPoker(String name, TreeSet<Integer> ts, HashMap<Integer, String> hashMap) {
        System.out.print(name + "的牌是：");
        for (Integer key : ts) {
            String value = hashMap.get(key);
            System.out.print(value + " ");
        }
        System.out.println();
    }
    public static void main(String[] args) {
        DouDiZhu02 douDiZhu = new DouDiZhu02();
        douDiZhu.init();
        douDiZhu.ShuffleCards();
        douDiZhu.LicensePlate();
    }
}
